package work;

import java.util.ArrayList;
import java.util.List;

/**
 * 分页返回结果
 */
public class Pageination<T> {
    // 返回的数据
    private List<T> data = new ArrayList<>();
    private Integer totalPage;
    private Long totalSize;
    private Integer currentPage;

    public Pageination() {}

    public Pageination(List<T> data, Integer totalPage, Long totalSize, Integer currentPage) {
        this.data = data;
        this.totalPage = totalPage;
        this.totalSize = totalSize;
        this.currentPage = currentPage;
    }
    // springframework的Page转换成Pageination对象
    public static <T> Pageination<T> convert(Page<T> result) {
        Pageination<T> pageination = new Pageination();
        pageination.setData(result.getContent());
        pageination.setTotalPage(result.getTotalPages());
        return pageination;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Long getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(Long totalSize) {
        this.totalSize = totalSize;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }
}
